/*
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx;


/**
 *
 * @author jdp
 */
public class Tr
    extends Container
{

    public Tr(){
        super();
    }


    public void layout(){
        super.layout();
    }
    public Table getParentTable(){
        Component p = this.parent;
        if (p instanceof Table)
            return (Table)p;
        else {
            do {
                p = p.parent;

                if (p instanceof Table)
                    return (Table)p;
            }
            while (null != p);
            return null;
        }
    }
    public int getRows(){
        Table parent = this.getParentTable();
        if (null != parent)
            return parent.getRows();
        else
            return 0;
    }
    public int getColumns(){
        Table parent = this.getParentTable();
        if (null != parent)
            return parent.getColumns();
        else
            return 0;
    }
    public int getCellspacing(){
        Table p = this.getParentTable();
        if (null == p)
            return 0;
        else
            return p.getCellspacing();
    }
    public int getCellpadding(){
        Table p = this.getParentTable();
        if (null == p)
            return 0;
        else
            return p.getCellpadding();
    }
    public int countColumns(){
        int columns = 0;
        for (Component child : this){
            if (child instanceof Td){
                Td td = (Td)child;
                columns += Math.max(1,td.getColspan());
            }
        }
        return columns;
    }
    public void endElement(){
        int space = this.getCellspacing();
        if (0 < space){
            for (Component child : this){
                child.setMargin(space);
            }
        }
        int pad = this.getCellpadding();
        if (0 < space){
            for (Component child : this){
                child.setPadding(pad);
            }
        }
    }
    public void endElementTableRows(float pc, String pcString){

        for (Component child : this){
            if (child instanceof Td){
                Td td = (Td)child;
                float cs = td.getColspan();
                if (0f < cs){
                    pc *= cs;
                    String rs = String.valueOf(pc)+'%';
                    td.setRelative("width",rs);
                }
                else
                    td.setRelative("width",pcString);
            }
        }
    }
    protected boolean layoutAutoPosX(){
        return (this.isDisplayable());
    }
    protected boolean layoutAutoPosY(){
        return (this.isDisplayable());
    }
    protected boolean layoutAutoDimW(){
        return (this.isDisplayable());
    }
    protected boolean layoutAutoDimH(){
        return (this.isDisplayable());
    }
}
